package com.woniuxy.user.controller;

import com.woniuxy.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @Author: 曾令忠
 * @Description:
 * @Date: 2020/7/8 0008-下午 2:35
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @RequestMapping("/show")
    public String show(){
        return "my name is zhangsan";
    }
    @RequestMapping("/get")
    public Map get(Integer id){
//        Product product = restTemplate.getForObject("http://localhost:8001/product/get?id="+id, Product.class);
//        ServiceInstance serviceInstance = loadBalancerClient.choose("client");
//        String host = serviceInstance.getHost();
//        Integer port = serviceInstance.getPort();
        return restTemplate.getForObject("http://client/product/get?id="+id,Map.class);


    }

}
